package com.sxkj.service.pay;

import com.github.wxpay.sdk.WXPayConfig;
import com.github.wxpay.sdk.WXPayConstants;
import com.sxkj.common.pay.wxpay.WXPay;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author Zhang Xingliang
 * @description 只提供支付相关接口方法，与业务解耦，不允许写业务内容
 * @date 9:30 2020/1/3
 **/
@Service
public class WxPayService {

    @Autowired
    private WXPayConfig config;

    /*
        发红包
     */
    public Map<String, String> sendRedPack(Map<String, String> data) throws Exception {
            WXPay wxpay = new WXPay(config, true);
//            data.put("mch_billno", "sxkj" + System.currentTimeMillis());
//            data.put("send_name", config.getSendName());
            data.put("scene_id", "PRODUCT_1");
            data.put("re_openid", "o3jef0cZK5ThapWaw3YLVJG7_ovU");
            data.put("total_amount", String.valueOf(10));
            data.put("total_num", "1");
            data.put("wishing", config.getWishing());
            data.put("client_ip", config.getClientIp());
            data.put("act_name", config.getActName());
            data.put("remark", config.getRemark());
            Map<String, String> resp = wxpay.sendRedPack(data);
            //发送成功
            if (resp.get("return_code").equals(WXPayConstants.SUCCESS) && resp.get("result_code").equals(WXPayConstants.SUCCESS)) {

            } else {

            }

            // 返回状态码
            String return_code = resp.get("return_code");
            // 返回信息
            String return_msg = resp.get("return_msg");
            // 业务结果
            String result_code = resp.get("result_code");
            // 错误代码
            String err_code = resp.get("err_code");
            // 错误代码描述
            String err_code_des = resp.get("err_code_des");

            System.out.println(resp);

            return resp;
    }
}
